package com.gimi.cloud.bbp.dao.myMapper.core.provider.select;

import com.gimi.cloud.bbp.dao.myMapper.core.JrcsSqlHelper;
import org.apache.ibatis.mapping.MappedStatement;

import tk.mybatis.mapper.mapperhelper.MapperHelper;
import tk.mybatis.mapper.mapperhelper.MapperTemplate;
import tk.mybatis.mapper.mapperhelper.SqlHelper;

/**
 * 自定义查询条件
 * 
 * @author wbj
 * @date 2017-07-22
 */
public class JrcsSelectProvider extends MapperTemplate {
	public JrcsSelectProvider(Class<?> mapperClass, MapperHelper mapperHelper) {
		super(mapperClass, mapperHelper);
	}

	public String queryBy(MappedStatement ms) {
		Class<?> entityClass = getEntityClass(ms);
		setResultType(ms, entityClass);// 修改返回值类型为实体类型
		StringBuilder sql = new StringBuilder();
		sql.append(SqlHelper.selectAllColumns(entityClass));
		sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass)));
		sql.append(JrcsSqlHelper.queryByColumn(entityClass));
		sql.append(" limit 1");
		return sql.toString();
	}

	public String queryCountBy(MappedStatement ms) {
		Class<?> entityClass = getEntityClass(ms);
		StringBuilder sql = new StringBuilder();
		sql.append(SqlHelper.selectCount(entityClass));
		sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass)));
		sql.append(JrcsSqlHelper.queryByColumn(entityClass));
		return sql.toString();
	}

	public String queryListBy(MappedStatement ms) {
		Class<?> entityClass = getEntityClass(ms);
		setResultType(ms, entityClass);// 修改返回值类型为实体类型
		StringBuilder sql = new StringBuilder();
		sql.append(SqlHelper.selectAllColumns(entityClass));
		sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass)));
		sql.append(JrcsSqlHelper.queryByColumn(entityClass));
		return sql.toString();
	}

	public String queryCountByExclude(MappedStatement ms) {
		Class<?> entityClass = getEntityClass(ms);
		StringBuilder sql = new StringBuilder();
		sql.append(SqlHelper.selectCount(entityClass));
		sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass)));
		sql.append(JrcsSqlHelper.queryCountByExclude(entityClass));
		return sql.toString();
	}
}
